<?php 
include ("jpgraph-2.1.2/src/jpgraph.php"); 
include ("jpgraph-2.1.2/src/jpgraph_line.php"); 
include ("jpgraph-2.1.2/src/jpgraph_bar.php"); 

// Library files
include '../includes/variables.php';
include '../includes/cDates.php';
include '../includes/cPlayer.php';
include '../includes/cMember.php';
include '../includes/cDatabase.php';
include '../includes/cGame.php';

$position = array();

$cGame = new game;
$cGame->calculatePositionsPerWeek();

$cDates = new dates;
$currentWeek = $cDates->getCurrentWeek();

for ($i = 0; $i < $cGame->getNumOfMembers(); $i++)
{
	if ($cGame->cMember[$i]->getMemberName() == $memberName)
	{
		$ourMember = $i;
	}
}
	
// We need to manipulate the data for the graph. Position is displayed on the x axis in reverse
// order so we need to bodge the data.	
for ($week = 1; $week < $currentWeek; $week++)
{
	$position[$week-1] = ($cGame->getNumOfMembers() + 1) - $cGame->cMember[$ourMember]->getPosition($week);
}
for ($i = 0; $i < $cGame->getNumOfMembers(); $i++)
	$yAxis[$i] = $cGame->getNumOfMembers() - $i;	
 
// Create the graph. 
$graph = new Graph(500,300,"auto");     
$graph-> SetScale("textlin",1,$cGame->getNumOfMembers());
$graph->img->SetMargin(40,20,30,40); 
$graph->title->Set("Team Position Per Week"); 
$graph->title->SetFont(FF_FONT1,FS_BOLD);

// Setup axis titles
$graph->xaxis->title->Set("Week"); 
$graph->yaxis->title->Set("Position");
$graph->yaxis->SetTickLabels($yAxis);

// Create the linear plot 
$lineplot=new LinePlot($position); 
$lineplot->mark->SetType(MARK_FILLEDCIRCLE);
$lineplot->mark->SetWidth(2);
$lineplot->mark->SetColor('black');
$lineplot->mark->SetFillColor('red');

// Add the plots to the graph 
$graph->Add($lineplot); 

$graph->Stroke();

?> 

